package com.iwop.moto.controller;

import com.iwop.moto.auth.LoginAuth;
import com.iwop.moto.comm.ErrCode;
import com.iwop.moto.model.ResultModel;
import com.iwop.moto.model.SuperRecordModel;
import com.iwop.moto.service.FeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * liuwb 2016-07-20 08:57
 */
@Controller
public class FeedbackController extends  BaseController {

    @Autowired
    private FeedbackService feedbackService;

    /**
     * liuwb 2016-07-21 11:17
     * 功能:意见反馈 - 新增
     * 参数:userId 用户id
     * 参数:content 投诉内容
     */
    @RequestMapping("/api/feedback/add")
    @ResponseBody
    @LoginAuth(isval = true)
    public ResultModel addFeedback(){
        SuperRecordModel SRModel = this.getSRModel();
        try {
            SRModel.put("sid", UUID.randomUUID().toString());
            SRModel.put("userId",getParam("userId"));
            SRModel.put("content",getParam("content"));
            SRModel.put("addtime",new Date());
            SRModel.put("status","1");
            feedbackService.insertFeedback(SRModel);
            return getSucceed(ErrCode.SUCCEED);
        }catch (Exception e){
            e.printStackTrace();
            return getErr(ErrCode.ERROR_SYSTEM);
        }
    }

    /**
     * liuwb 2016-07-21 11:22
     * 功能:意见反馈 - 修改
     * 参数:sid 主键
     * 参数:content 投诉内容
     */
    @RequestMapping("/api/feedback/edit")
    @ResponseBody
    @LoginAuth(isval = true)
    public ResultModel editFeedback(){
        SuperRecordModel SRModel = this.getSRModel();
        try {
            feedbackService.updateFeedback(SRModel);
            return getSucceed(null);
        }catch (Exception e){
            e.printStackTrace();
            return getErr(ErrCode.ERROR_SYSTEM);
        }
    }

    /**
     * liuwb 2016-07-21 11:22
     * 功能:意见反馈 - 列表
     */
    @RequestMapping("api/feedback/list")
    @ResponseBody
    @LoginAuth(isval = true)
    public ResultModel findFeedbackList(){
        SuperRecordModel SRModel = this.getSRModel();
        try {
            List<SuperRecordModel> lists = feedbackService.findFeedbackList(SRModel);
            if(lists.size() == 0){
                return getErr(ErrCode.ERROR_NOCOUNT);
            }
            return getSucceed(lists);
        }catch (Exception e){
            e.printStackTrace();
            return getErr(ErrCode.ERROR_SYSTEM);
        }
    }




}
